#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(int argc, char const *argv[])
{
    /* 随机数
    srand(time(0));
    int a = rand();

    printf("%d\n", a);
    */

    srand(time(0));
    // 生成一个1到100的随机数
    int number = rand() % 100 + 1;
    int count;
    int a = 0;
    int retry;
    do
    {
        count = 0;
        printf("Guess a number from 1 to 100!\n");
        printf("(Input -1 to quit at any time)\n");
        do
        {
            printf("Have a try: \n");
            scanf("%d", &a);
            count++;
            if (a == -1)
            {
                break;
            }
            else if (a > number)
            {
                printf("Too large!\n");
            }
            else if (a < number)
            {
                printf("Too small!\n");
            }
            else
            {
                printf("Exactly! You've got the answer with only \
                    %d turns!\n", count);
            }
        } while (a != number);
        printf("Wanna retry? Input 0 to exit and default to replay.\n");
        scanf("%d", &retry);
    } while (retry != 0);
    
    return 0;
}